#include "mytextedit.h"

#include <QWheelEvent>

myTextEdit::myTextEdit(QWidget *parent):QTextEdit(parent)
{

}

void myTextEdit::wheelEvent(QWheelEvent *e)
{
    if(isPressed){
        if(e->angleDelta().y()>0){
            zoomIn();
        }
        else if(e->angleDelta().y() < 0){
            zoomOut();
        }
        e->accept();
    }
    else{
        QTextEdit::wheelEvent(e);
    }
}

void myTextEdit::keyPressEvent(QKeyEvent *e)
{
    if(e->key() == Qt::Key_Control){
        isPressed = 1;
    }
    else{
        QTextEdit::keyPressEvent(e); // 不要影响其他键的正常使用
    }
}

void myTextEdit::keyReleaseEvent(QKeyEvent *e)
{
    if(e->key() == Qt::Key_Control){
        isPressed = 0;
    }
    else{
        QTextEdit::keyPressEvent(e);
    }
}
